package com.itheima.d1_Collection_Api;

import java.util.*;

/**
 * Collection常用Api：toArray,contains,isEmpty,clear
 */
public class demo1 {
    public static void main(String[] args) {
        //hashset
        Collection<Integer> list1 = new HashSet();

        //1.add
        list1.add(111);
        list1.add(2222);
        list1.add(3333);
        list1.add(111);
        System.out.println(list1);
        //2.clear
        //list1.clear();

        //3.isEmpty
        System.out.println(list1.isEmpty());

        //4.size
        System.out.println(list1.size());

        //5.contains
        System.out.println(list1.contains(111));

        //6.remove,如果有多个会默认删除前面的第一个
        Collection list =new ArrayList();//经典写法，类似多态
        list.add(111);
        list.add(2222);
        list.add(3333);
        list.add(111);
        System.out.println(list);
        list.remove(111);
        System.out.println(list);

        //7.toArray,转换为数组
        Object[] arr = list.toArray();
        System.out.println(Arrays.toString(arr));


        //8.addAll,将list4加入到list3
        Collection list3 =new ArrayList();
        list3.add(1);
        list3.add(1);
        list3.add(1);
        Collection list4 =new ArrayList();
        list4.add(2);
        list4.add(2);
        list4.add(2);
        list3.addAll(list4);
        System.out.println(list3);


    }
}
